home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / disk / cdrom / MusicBox-2.1os.lha / MusicBox / MusicBoxJoystick.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-29  |  5.5 KB  |  252 lines

  1. /*
  2.  ##########################################################################
  3.  ####                                                                  ####
  4.  ####                        The MusicBox Project                      ####
  5.  ####                    ============================                  ####
  6.  ####                                                                  ####
  7.  #### MusicBoxJoystick.c                                               ####
  8.  ####                                                                  ####
  9.  #### Version 2.1os  --  September 29, 2000                            ####
  10.  ####                                                                  ####
  11.  #### Copyright (C) 1994  Thomas Dreibholz                             ####
  12.  ####               2000  Molbachweg 7                                 ####
  13.  ####                     51674 Wiehl                                  ####
  14.  ####                     Germany                                      ####
  15.  ####                                                                  ####
  16.  ####                     EMail: Dreibholz@bigfoot.com                 ####
  17.  ####                     WWW:   http://www.bigfoot.com/~dreibholz     ####
  18.  ####                                                                  ####
  19.  ##########################################################################
  20. */
  21. /***************************************************************************
  22.  *                                                                         *
  23.  *   This program is free software; you can redistribute it and/or modify  *
  24.  *   it under the terms of the GNU General Public License as published by  *
  25.  *   the Free Software Foundation; either version 2 of the License, or     *
  26.  *   (at your option) any later version.                                   *
  27.  *                                                                         *
  28.  ***************************************************************************/
  29.  
  30. /* Joystick-Kontrolle */
  31.  
  32. #include "MusicBox.h"
  33.  
  34. #define JOYSTICK_LEFT  (1L<<9)
  35. #define JOYSTICK_RIGHT (1L<<1)
  36. #define JOYSTICK_UP    (1L<<8)
  37. #define JOYSTICK_DOWN  (1L<<0)
  38. #define FIRE           (1L<<7)
  39.  
  40. extern struct Einstellungen  Einstellungen;
  41. extern struct RastPort      *RPort;
  42.  
  43. UWORD joy;
  44. UBYTE fire;
  45.  
  46. extern BOOL IsIconify;
  47.  
  48. #asm
  49.    public _GetJ1
  50. _GetJ1:
  51.    move.w $dff00c,d0
  52.    move.w d0,_joy
  53.  
  54.    btst #7,$bfe001
  55.    bne 1$
  56.    move.b #1,d0
  57.    jmp 2$
  58. 1$:
  59.    move.b #0,d0
  60. 2$:
  61.    move.b d0,_fire
  62.    rts
  63. #endasm
  64.  
  65. BOOL XOR(a,b)
  66.  UWORD a,b;
  67. {
  68.  return((a || b) && !(a && b));
  69. }
  70.  
  71. BOOL Right()
  72. {
  73.  if((joy & JOYSTICK_RIGHT)) return(TRUE);
  74.  return(FALSE);
  75. }
  76.  
  77. BOOL Left()
  78. {
  79.  if((joy & JOYSTICK_LEFT)) return(TRUE);
  80.  return(FALSE);
  81. }
  82.  
  83. BOOL Up()
  84. {
  85.  return(XOR(Left(joy),(joy & JOYSTICK_UP)));
  86. }
  87.  
  88. BOOL Down()
  89. {
  90.  return(XOR(Right(joy),(joy & JOYSTICK_DOWN)));
  91. }
  92.  
  93. void JoystickHandler()
  94. {
  95.  REGISTER BOOL  bool;
  96.  REGISTER UWORD j;
  97.  REGISTER BYTE  x,y,nx,ny;
  98.  
  99.  GetJ1();
  100.  y=x=0;
  101.  if(Left()) x=-1;
  102.  if(Right()) x=1;
  103.  if(Up()) y=1;
  104.  if(Down()) y=-1;
  105.  
  106.  if((x==0)&&(y==0)) return;
  107.  
  108.  if(IsIconify==FALSE)
  109.   {
  110.    SetAPen(RPort,FARBE);
  111.    PutText(5+(3*22),35,"W");
  112.   }
  113.  
  114.  if(Einstellungen.Kontrolle==JOYSTICK_I)
  115.   {
  116.  
  117.    do
  118.     {
  119.      Delay(1);
  120.      GetJ1();
  121.      ny=nx=0;
  122.      if(Left()) nx=-1;
  123.      if(Right()) nx=1;
  124.      if(Up()) ny=1;
  125.      if(Down()) ny=-1;
  126.     }
  127.    while((nx!=0)||(ny!=0));
  128.  
  129.    if(IsIconify==FALSE)
  130.      PutText(5+(3*22),35," ");
  131.  
  132.    if(fire==1) return;
  133.    if(Einstellungen.Funktion==STANDBY) return;
  134.   
  135.    switch(y)
  136.     {
  137.      case 1:
  138.        WiedergabeClicked();
  139.       break;
  140.      case 0:
  141.        switch(x)
  142.         {
  143.          case -1:
  144.            MinusClicked();
  145.           break;
  146.          case 1:
  147.            PlusClicked();
  148.           break;
  149.         }
  150.       break;
  151.      case -1:
  152.        StopClicked();
  153.       break;
  154.     }
  155.   }
  156.  else
  157.   {
  158.    bool=FALSE;
  159.    do
  160.     {
  161.      Delay(1);
  162.      GetJ1();
  163.      ny=nx=0;
  164.      if(Left()) nx=-1;
  165.      if(Right()) nx=1;
  166.      if(Up()) ny=1;
  167.      if(Down()) ny=-1;
  168.      if((nx==0)&&(ny==0)) bool=TRUE;
  169.      if(fire==1) bool=TRUE;
  170.     } while(bool==FALSE);
  171.    bool=FALSE;
  172.    if(ny==-1)
  173.     {
  174.      if(nx!=0)
  175.       {
  176.        if(nx==-1)
  177.         {
  178.          if(Einstellungen.VolumenL>=8)
  179.            Einstellungen.VolumenL-=8;
  180.          else
  181.            Einstellungen.VolumenL=0;
  182.          if(Einstellungen.VolumenR>=8)
  183.            Einstellungen.VolumenR-=8;
  184.          else
  185.            Einstellungen.VolumenR=0;
  186.         }
  187.        else
  188.         {
  189.          if(Einstellungen.VolumenL<=247)
  190.            Einstellungen.VolumenL+=8;
  191.          else
  192.            Einstellungen.VolumenL=255;
  193.          if(Einstellungen.VolumenR<=247)
  194.            Einstellungen.VolumenR+=8;
  195.          else
  196.            Einstellungen.VolumenR=255;
  197.         }
  198.        Volumen();
  199.        ZeigeVolumen();
  200.        return;
  201.       }
  202.     }
  203.  
  204.    do
  205.     {
  206.      Delay(1);
  207.      GetJ1();
  208.      ny=nx=0;
  209.      if(Left()) nx=-1;
  210.      if(Right()) nx=1;
  211.      if(Up()) ny=1;
  212.      if(Down()) ny=-1;
  213.      if((nx==0)&&(ny==0)) bool=TRUE;
  214.      if(fire==0) bool=TRUE;
  215.     } while(bool==FALSE);
  216.  
  217.    if(IsIconify==FALSE)
  218.      PutText(5+(3*22),35," ");
  219.  
  220.    if((nx==0)&&(ny==0)) return;
  221.      if(Einstellungen.Funktion==STANDBY) return;
  222.  
  223.    switch(ny)
  224.     {
  225.      case 1:
  226.        switch(nx)
  227.         {
  228.          case -1:
  229.            RuecklaufClicked();
  230.           break;
  231.          case 0:
  232.             WiedergabeClicked();
  233.           break;
  234.          case 1:
  235.             VorlaufClicked();
  236.           break;
  237.         }
  238.       break;
  239.      case 0:
  240.        if(nx==-1)
  241.          MinusClicked();
  242.        else
  243.          PlusClicked();
  244.       break;
  245.      case -1:
  246.        StopClicked();
  247.       break;
  248.     }
  249.   }
  250. }
  251.  
  252.